package per.mapt.spring;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import per.mapt.webservice.HelloService;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * Created by mapeif on 2017/3/12.
 */
@Controller
@RequestMapping(value = "/login")
public class LoginController {
    @Autowired
    private HelloService service;

    @RequestMapping(value = "/admin", method = RequestMethod.POST)
    public String login(@RequestParam String user, @RequestParam String passwd, HttpSession session) {
        session.removeAttribute("userid");
        service.sayHi("wjl");
        if("wjl".equals(user)&&"520".equals(passwd)){
            session.setAttribute("userid",user);
            return "redirect:/ok.jsp";
        }
        HttpServletRequest req = null;
        req.getAsyncContext();
        System.out.println(session.getAttribute("userid"));
        return "redirect:/";
    }

    public HelloService getService() {
        return service;
    }

    public void setService(HelloService service) {
        this.service = service;
    }
}
